package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.CarouselReq;
import com.sbj.dto.res.CarouselRes;
import com.sbj.entity.Carousel;
import com.sbj.service.CarouselService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/9 16:50
 */
@RestController
@RequestMapping(value = "/carousel")
@AllArgsConstructor
public class CarouselController implements BaseCommonInterface<CarouselReq, CarouselRes> {

    private final CarouselService carouselService;

    @Override
    public Result<String> save(@Valid CarouselReq carouselReq) {
        carouselService.saveOrUpdate(Convert.convert(Carousel.class, carouselReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        carouselService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<CarouselRes>> lists(CarouselReq carouselReq) {
        return Result.successResult(carouselService.lists(carouselReq));
    }

    @Override
    public Result<CarouselRes> findById(Integer id) {
        return Result.successResult(Convert.convert(CarouselRes.class,carouselService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<CarouselRes> list) {
        return null;
    }
}
